Skip to content

[6.x] Move testing traits into Statamic\Testing\Concerns - #15115

Merged
jasonvarga merged 6 commits into
6.xfrom
testing-concerns
Aug 5, 2026
Merged

[6.x] Move testing traits into Statamic\Testing\Concerns#15115
jasonvarga merged 6 commits into
6.xfrom
testing-concerns

Conversation

@duncanmcclean

@duncanmcclean duncanmcclean commented Aug 4, 2026

Copy link
Copy Markdown
Member

This pull request moves four test traits out of core's Tests namespace and into Statamic\Testing\Concerns, so addons using AddonTestCase can use them too.

Statamic's Control Panel routes are permission-guarded, so any addon testing them needs to build users with and without a given permission. Core already has exactly that helper in tests/FakesRoles.php, but the Tests namespace isn't autoloadable from an addon package — so addon authors end up hand-copying it. statamic/forms-pro currently carries a trimmed copy for its Slack connection tests, and can delete it once this lands.

The traits that have moved:

  • FakesRoles
  • FakesUserGroups
  • ElevatesSessions
  • FakesViews

This follows the same approach as PreventsSavingStacheItemsToDisk in #9871 — the trait body moves to src/Testing/Concerns, and the file in tests becomes a thin trait that uses it. That keeps the 176 core test files importing these traits untouched.

FakesViews also declared FakeViewEngine, FakeViewFactory and FakeViewFinder in the same file. They've each been given their own file, so they're autoloadable rather than relying on the trait's file having been loaded first. FakesUserGroups::setTestUserGroups() is now protected rather than private, to match the other concerns.

No changes were needed to AddonTestCase. It detects PreventsSavingStacheItemsToDisk via class_uses_recursive() only because that trait needs setUp/tearDown hooks — none of these four do, so addons can just use them directly.

duncanmcclean and others added 6 commits August 4, 2026 13:01
so addons using `AddonTestCase` can build users with and without a
given permission, instead of hand-copying the trait.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`setTestUserGroups()` becomes `protected` to match the other concerns.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`FakeViewEngine`, `FakeViewFactory` and `FakeViewFinder` get their own
files, so they're autoloadable rather than relying on the trait's file
being loaded first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
They're concrete classes, not traits, so they don't belong in `Concerns`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`FakeViewFactory` is constructed alongside the engine, so it can hold a
reference directly instead of reaching through a generic container key
that addons could collide with.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jasonvarga
jasonvarga merged commit 168f92a into 6.x Aug 5, 2026
23 checks passed
@jasonvarga
jasonvarga deleted the testing-concerns branch August 5, 2026 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants